package com.example.demo.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-10-12
 * Time: 15:58
 */

@RestControllerAdvice
public class MyExceptionAdvice implements WebMvcConfigurer {


    @ExceptionHandler(Exception.class) //直接处理父类
    public HashMap<String,Object> arithmeticExceptionAdvice(ArithmeticException e){
        HashMap<String,Object> result = new HashMap<>();
        result.put("state",-1);
        result.put("data",null);
        result.put("msg",e.getMessage());
        return  result;
    }

}
